#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <signal.h>
#include <error.h>
#include <json-c/json.h>
#include <json-c/json_object.h>
#define BUFFER_SIZE 64
#define PORT 8888
#define CLIENT_IP "172.23.232.7"
#define SERVER_IP "0,0,0,0"
int main()
{

    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd == -1)
    {
        perror("socket error");
        exit(-1);
    }
    char revMassage[BUFFER_SIZE];
    memset(&revMassage, 0, sizeof(revMassage));

    char sendMassage[BUFFER_SIZE];
    memset(&sendMassage, 0, sizeof(sendMassage));
    strncpy(sendMassage, "world", sizeof(sendMassage) - 1);
    int ret = 0;
    struct sockaddr_in serverAddr;
    serverAddr.sin_family = AF_INET;
    serverAddr.sin_port = htons(PORT);
    ret = inet_pton(AF_INET, SERVER_IP, (void *)&serverAddr.sin_addr.s_addr);
    if (ret == -1)
    {
        perror("inet_pton error");
    }
    socklen_t serverAddrLen = sizeof(serverAddr);
    while (1)
    {
        ret = sendto(sockfd, (void *)sendMassage, sizeof(sendMassage), 0, (struct sockaddr *)&serverAddr, serverAddrLen);
        if (ret <= 0)
        {
            perror("sendto error");
            close(sockfd);
            exit(-1);
            break;
        }
        ret = recvfrom(sockfd, (void *)revMassage, sizeof(revMassage), 0, NULL, NULL);
        if (ret <= 0)
        {
            perror("recvfrom error");
            close(sockfd);
            exit(-1);
            break;
        }
        printf("server message=%s\n", revMassage);
        sleep(2);
    }
    close(sockfd);
    return 0;
}